<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function init() {
		parent::init();
               //Validator::set_javascript_validation_handler('none'); 
				
		Requirements::javascript("http://ajax1.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js");
		Requirements::javascript("http://ajax1.microsoft.com/ajax/jquery.validate/1.8/jquery.validate.min.js");
		
		Requirements::customScript('
			jQuery(document).ready(function() {
                                alert("aaa");
			});
		');
		
		// Note: you should use SS template require tags inside your templates 
		// instead of putting Requirements calls here.  However these are 
		// included so that our older themes still work
		Requirements::themedCSS('layout'); 
		Requirements::themedCSS('typography'); 
		Requirements::themedCSS('form'); 
}
class Contact extends Page {

	public static $db = array(
             'Mailto' => 'vochicong57@yahoo.com', //Email address to send submissions to

      'SubmitText' => 'HTMLText' //Text presented after submitting message 
	);
        
        function getCMSFields() {

      $fields = parent::getCMSFields();

   

      $fields->addFieldToTab("Root.Content.OnSubmission", new TextField('Mailto', 'Email submissions to'));   

      $fields->addFieldToTab("Root.Content.OnSubmission", new HTMLEditorField('SubmitText', 'Text on Submission'));   

   

      return $fields;   

   }
	public static $has_one = array(
	);

}
class StyleTextFile extends TextField{
    function jsValidation() {
        $formID = $this->form->FormName();
        $jsFunc =<<<JS
        $(document).ready(function() {
            var el = _CURRENT_FORM.elements[fieldName];
             alert(el.id);
        });
        
});
JS;
Requirements::customScript($jsFunc, 'func_validateNumber');

return "\$('$formID').document();";
    }
}
class MyForm extends Form {
 
   function __construct($controller, $name) {
      $fields = new FieldSet(
         new TextField('name', 'Your Name'),
         new TextField('age', 'Age'),
         new TextField('address','Address'),
         new EmailField('email','Email'),
         new TextareaField('message','Your Message')
      );
 
      $actions = new FieldSet(
         new FormAction('submit')
      );
 
      parent::__construct($controller, $name, $fields, $actions);
   }
 
   function forTemplate() {
      return $this->renderWith(array(
         $this->class,
         'Form'
      ));
   }
 
   function submit($data, $form) {
      // do stuff here
        $From = 'vochicong57@gmail.com';
        $To = 'vochicong57@yahoo.com.vn';
        $Subject = 'Website Contact message';  
         $body='sfgsfgsdgs';
        $email = new Email($From, $To, $Subject,$body);
        //set template
       // $email->setTemplate('ContactEmail');
        //populate template
      //  $email->populateTemplate($data);
        //send mail
        $email->send();


       // $form->sessionMessage('Thanks for contacting us. We\'ll get in touch with you as soon as possible!'); 
       // Director::redirectBack();
        //return to submitted message
      //  Director::redirect($this->Link("?success=1"));
   }
    public function Success()

   {

      return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";

   } 
}


class Contact_Controller extends Page_Controller {
    function ContactForm()
    {
       
        return new MyForm($this, 'ContactForm');
    }
    
}
?>
